const dbName='test';
const dbPath='_doc/test.db';

export default{
	createDatabase(){
		console.log("正在创建连接...");
		let isOpen=plus.sqlite.isOpenDatabase({
			name:dbName,
			path:dbPath
		});
		if(isOpen)
		{
			console.log("如果连接已经打开");
			return Promise.resolve();
		}
		return new Promise((resolve,reject)=>{
			console.log("连接成功！");
			console.log("打开数据库");
			plus.sqlite.openDatabase({
				name:dbName,
				path:dbPath,
				success:resolve,//result=>resolve(result),
				fail:reject//err=>reject(err)
			});
		});
	},
	selectSql(sql){
		console.log('查询：',sql)
		return new Promise((resolve,reject)=>{ 
			plus.sqlite.selectSql({
				name:dbName,
				sql,
				success:resolve,
				fail:reject
			});
			console.log("能执行到这里");
		});
	},
	executeSql(sql){
		console.log('执行:',sql);
		return new Promise((resolve,reject)=>{
			plus.sqlite.executeSql(({
				name:dbName,
				sql,
				success:resolve,
				fail:reject
			}))
		})
	}
}